extends ../layout

block content
  .container
    .row
      form.form-horizontal(method="post", action="/nodeport/admin/movie", enctype="multipart/form-data")
        .form-group
          label.col-sm-2.control-label 豆瓣同步
          .col-sm-10
            input#douban.form-control(type="text")
        if movie._id
          input(type="hidden", name="_id", value=movie._id)
        .form-group
          label.col-sm-2.control-label(for="inputCategory") 电影分类
          .col-sm-10
            input#inputCategory.form-control(type="text", name="categoryName", value=movie.categoryName)
        .form-group
          label.col-sm-2.control-label 分类选择
          each cat in categories
            label.radio-inline
              if movie.category
                input(type="radio", name="category", value=cat._id, checked=cat._id.toString()==movie.category.toString())
              else
                input(type="radio", name="category", value=cat._id)
              | #{cat.name}
        .form-group
          label.col-sm-2.control-label(for="inputTitle") 电影名字
          .col-sm-10
            input#inputTitle.form-control(type="text", name="title", value=movie.title)
        .form-group
          label.col-sm-2.control-label(for="inputDoctor") 电影导演
          .col-sm-10
            input#inputDoctor.form-control(type="text", name="doctor", value=movie.doctor)
        .form-group
          label.col-sm-2.control-label(for="inputCountry") 国家
          .col-sm-10
            input#inputCountry.form-control(type="text", name="country", value=movie.country)
        .form-group
          label.col-sm-2.control-label(for="inputLanguage") 语种
          .col-sm-10
            input#inputLanguage.form-control(type="text", name="language", value=movie.language)
        .form-group
          label.col-sm-2.control-label(for="inputPoster") 海报地址
          .col-sm-10
            input#inputPoster.form-control(type="text", name="poster", value=movie.poster)
        .form-group
          label.col-sm-2.control-label(for="uploadPoster") 海报上传
          .col-sm-10
            input#uploadPoster(type="file", name="uploadPoster")
        .form-group
          label.col-sm-2.control-label(for="inputFlash") 片源地址
          .col-sm-10
            input#inputFlash.form-control(type="text", name="flash", value=movie.flash)
        .form-group
          label.col-sm-2.control-label(for="inputYear") 上映年代
          .col-sm-10
            input#inputYear.form-control(type="text", name="year", value=movie.year)
        .form-group
          label.col-sm-2.control-label(for="inputSummary") 电影简介
          .col-sm-10
            textarea#inputSummary.form-control(type="text", name="summary")= movie.summary
        .form-group
          .col-sm-offset-2.col-sm-10
          button.btn.btn-default(type="submit") 录入
  script.
    $(function() {
      $('#douban').blur(function() {
        var douban = $(this)
        var id = douban.val()

        if (id) {
          $.ajax({
            url: 'https://api.douban.com/v2/movie/subject/' + id,
            cache: true,
            type: 'get',
            dataType: 'jsonp',
            crossDomain: true,
            jsonp: 'callback',
            success: function(data) {
              $('#inputTitle').val(data.title)
              $('#inputDoctor').val(data.directors[0].name)
              $('#inputCountry').val(data.countries[0])
              $('#inputPoster').val(data.images.large)
              $('#inputYear').val(data.year)
              $('#inputSummary').val(data.summary)
            }
          })
        }
      })
    })